package com.hzit.cart.controller;

import com.hzit.cart.api.domain.Order;
import com.hzit.cart.service.IOrderService;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2023-09-21
 */
@RestController
@RequestMapping("/order")
public class OrderController {

	@Autowired
	private IOrderService orderService;

	//1. 保存订单
	@PostMapping("/saveOrder")
	R saveOrder(@RequestBody Order order) {
		orderService.save(order);
		return R.ok();
	}
	//2. 查询订单列表
	@GetMapping("/{login}")
	R<List<Order>> getOrderList(@PathVariable("login") String login){
		List<Order> orders = orderService.getOrderList(login);
		return R.ok(orders);
	}
	//3. 修改订单的状态
	@PutMapping("/update/{id}/{status}")
	R updateOrder(@PathVariable("id") String id, @PathVariable("status") String status){
		Order order = new Order();
		order.setOrderId(Long.parseLong(id));
		order.setStatus(status);
		orderService.updateById(order);
		return R.ok();
	}
}
